"""
Agents: central classes that received notifications and forward them to
connector objects.
"""



import time

from zope.interface import implements

from pymx.interfaces import IMonitorAgent



class MonitorAgent(object):
    """
    @ivar seconds: method providing timing value for monitored items.
    @type seconds: C{func}

    @ivar _subscribers: list of subscribed connectors.
    @type _subscribers: C{list}
    """
    implements(IMonitorAgent)
    seconds = time.time

    def __init__(self):
        self._subscribers = []


    def registerConnector(self, connector):
        self._subscribers.append(connector)


    def unregisterConnector(self, connector):
        self._subscribers.remove(connector)


    def registerItem(self, item):
        item.__agent__ = self


    def attributeSetNotification(self, item, name, value):
        for connector in self._subscribers:
            connector.attributeSetNotification(item, name, value)


    def methodCallNotification(self, item, method, args, kwargs, time):
        for connector in self._subscribers:
            connector.methodCallNotification(item, method, args, kwargs, time)
